package com.bifrost.entity;

import com.bifrost.constant.CouponStatus;

import java.io.Serializable;
import javax.persistence.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import java.util.List;


/**
 * The persistent class for the COUPON_DETAIL database table.
 */
@Entity
@Table(name = "COUPON_DETAIL",indexes = {
        @Index(name = "INDEX_COUPON_CODE",columnList = "COUPON_CODE",unique = true)
})
@NamedQuery(name = "CouponDetail.findAll", query = "SELECT c FROM CouponDetail c")
public class CouponDetail implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "COUPON_DETAIL_ID", unique = true, nullable = false)
    private Long couponDetailId;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "ADD_TIME")
    private Date addTime = new Date();

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "ACTIVE_END_DATE", nullable = false)
    private Date activeEndDate;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "ACTIVE_START_DATE", nullable = false)
    private Date activeStartDate;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "CONSUMED_TIME")
    private Date consumedTime;

    @Column(name = "COUPON_CODE")
    private long couponCode;

    @Column(name = "COUPON_STATUS", length = 32, nullable = false)
    private String couponStatus = CouponStatus.UNUSED;

    @Column(name = "IS_USED", nullable = false)
    private Boolean isUsed = false;

    @Column(name = "RELEASE_MODE", length = 32)
    private String releaseMode;


    @Column(name = "FOR_ORDER_TYPE")
    private String forOrderType;

    @Column(name = "STACKED_WITH_OTHER")
    private Boolean stackedWithOther = false;

    @Column(name = "RELATED_TARGET_QUANTITY", precision = 11)
    private Integer relatedTargetQuantity = 0;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "RELEASE_BY",foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private MerchantStore releaseBy;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "RELEASE_DATE_END")
    private Date releaseDateEnd;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "RELEASE_DATE_START")
    private Date releaseDateStart;

    @Column(name = "IS_REFUNDABLE")
    private Boolean isRefundable = false;

    @Column(name = "IS_SHAREABLE")
    private Boolean isShareable = false;

    @Column(name = "MAX_USE_PER_ORDER")
    private Integer maxUsePerOrder;

    @Column(name = "MAX_USES_PER_CUSTOMER")
    private Integer maxUsesPerCustomer;

    @Column(name = "MERCHANT_ID")
    private Long merchantId;

    @Column(name = "ORDER_MIN_TOTAL", precision = 19, scale = 5, nullable = false)
    private BigDecimal orderMinTotal;

    @Column(name = "VALIDITY_TYPE", length = 64)
    private String validityType;

    @Column(name = "VALIDITY_DAYS", precision = 11)
    private Integer validityDays;
    @Column(name = "DISCOUNT_TYPE", length = 64)
    private String discountType;
    @Column(name = "DISCOUNT_AMOUNT", precision = 19, scale = 5)
    private BigDecimal discountAmount;

    @Column(name = "IS_COMBINABLE")
    private Boolean isCombinable = false;

    @Column(name = "COUPON_DESCRIPTION", length = 255)
    private String couponDescription;

    @Column(name = "COUPON_NAME", length = 100)
    private String couponName;

    @Column(name = "COUPON_TYPE_CODE", length = 64, nullable = false)
    private String couponTypeCode;

    /**
     * 外部规则码
     * */
    @Column(name = "RULE_CODE",length = 32)
    private String ruleCode;
    /**
     * 券标识
     * */
    @Column(name = "FLAG",length = 16)
    private String flag;

    /**
     * 消费码
     * */
    @Column(name = "CONSUME_CODE",length = 32)
    private String consumeCode;

    /**
     * 消费码生成时间
     * */
    @Column(name = "GENERATED_TIME")
    @Temporal(TemporalType.TIMESTAMP)
    private Date generatedTime;

    /**
     * 兑换所需积分
     * */
    @Column(name = "BONUS_POINTS")
    private BigInteger bonusPoints = BigInteger.ZERO;
    /**
     * 购买所需金额
     */
    @Column(name = "PRICE")
    private BigDecimal price = BigDecimal.ZERO;

    //bi-directional many-to-one association to Coupon
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "COUPON_ID",foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private Coupon coupon;

    //bi-directional many-to-one association to Customer
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CUSTOMER_ID",foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private Customer customer;

    @OneToMany(mappedBy = "couponDetail")
    @org.hibernate.annotations.ForeignKey(name = "none")
    private List<OrderCoupon> orderCoupons;

    public Long getCouponDetailId() {
        return couponDetailId;
    }

    public void setCouponDetailId(Long couponDetailId) {
        this.couponDetailId = couponDetailId;
    }

    public Date getAddTime() {
        return addTime;
    }

    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }

    public Date getActiveEndDate() {
        return activeEndDate;
    }

    public void setActiveEndDate(Date activeEndDate) {
        this.activeEndDate = activeEndDate;
    }

    public Date getActiveStartDate() {
        return activeStartDate;
    }

    public void setActiveStartDate(Date activeStartDate) {
        this.activeStartDate = activeStartDate;
    }

    public long getCouponCode() {
        return couponCode;
    }

    public void setCouponCode(long couponCode) {
        this.couponCode = couponCode;
    }

    public String getCouponStatus() {
        return couponStatus;
    }

    public void setCouponStatus(String couponStatus) {
        this.couponStatus = couponStatus;
    }

    public Boolean getIsUsed() {
        return isUsed;
    }

    public void setIsUsed(Boolean used) {
        isUsed = used;
    }

    public String getReleaseMode() {
        return releaseMode;
    }

    public void setReleaseMode(String releaseMode) {
        this.releaseMode = releaseMode;
    }

    public String getForOrderType() {
        return forOrderType;
    }

    public void setForOrderType(String forOrderType) {
        this.forOrderType = forOrderType;
    }

    public Boolean getStackedWithOther() {
        return stackedWithOther;
    }

    public void setStackedWithOther(Boolean stackedWithOther) {
        this.stackedWithOther = stackedWithOther;
    }

    public Integer getRelatedTargetQuantity() {
        return relatedTargetQuantity;
    }

    public void setRelatedTargetQuantity(Integer relatedTargetQuantity) {
        this.relatedTargetQuantity = relatedTargetQuantity;
    }

    public MerchantStore getReleaseBy() {
        return releaseBy;
    }

    public void setReleaseBy(MerchantStore releaseBy) {
        this.releaseBy = releaseBy;
    }

    public Date getReleaseDateEnd() {
        return releaseDateEnd;
    }

    public void setReleaseDateEnd(Date releaseDateEnd) {
        this.releaseDateEnd = releaseDateEnd;
    }

    public Date getReleaseDateStart() {
        return releaseDateStart;
    }

    public void setReleaseDateStart(Date releaseDateStart) {
        this.releaseDateStart = releaseDateStart;
    }

    public Boolean getRefundable() {
        return isRefundable;
    }

    public void setRefundable(Boolean refundable) {
        isRefundable = refundable;
    }

    public Boolean getShareable() {
        return isShareable;
    }

    public void setShareable(Boolean shareable) {
        isShareable = shareable;
    }

    public Integer getMaxUsePerOrder() {
        return maxUsePerOrder;
    }

    public void setMaxUsePerOrder(Integer maxUsePerOrder) {
        this.maxUsePerOrder = maxUsePerOrder;
    }

    public Integer getMaxUsesPerCustomer() {
        return maxUsesPerCustomer;
    }

    public void setMaxUsesPerCustomer(Integer maxUsesPerCustomer) {
        this.maxUsesPerCustomer = maxUsesPerCustomer;
    }

    public Long getMerchantId() {
        return merchantId;
    }

    public void setMerchantId(Long merchantId) {
        this.merchantId = merchantId;
    }

    public BigDecimal getOrderMinTotal() {
        return orderMinTotal;
    }

    public void setOrderMinTotal(BigDecimal orderMinTotal) {
        this.orderMinTotal = orderMinTotal;
    }

    public String getValidityType() {
        return validityType;
    }

    public void setValidityType(String validityType) {
        this.validityType = validityType;
    }

    public Integer getValidityDays() {
        return validityDays;
    }

    public void setValidityDays(Integer validityDays) {
        this.validityDays = validityDays;
    }

    public String getDiscountType() {
        return discountType;
    }

    public void setDiscountType(String discountType) {
        this.discountType = discountType;
    }

    public BigDecimal getDiscountAmount() {
        return discountAmount;
    }

    public void setDiscountAmount(BigDecimal discountAmount) {
        this.discountAmount = discountAmount;
    }

    public Boolean getCombinable() {
        return isCombinable;
    }

    public void setCombinable(Boolean combinable) {
        isCombinable = combinable;
    }

    public String getCouponDescription() {
        return couponDescription;
    }

    public void setCouponDescription(String couponDescription) {
        this.couponDescription = couponDescription;
    }

    public String getCouponName() {
        return couponName;
    }

    public void setCouponName(String couponName) {
        this.couponName = couponName;
    }

    public String getCouponTypeCode() {
        return couponTypeCode;
    }

    public void setCouponTypeCode(String couponTypeCode) {
        this.couponTypeCode = couponTypeCode;
    }

    public Coupon getCoupon() {
        return coupon;
    }

    public void setCoupon(Coupon coupon) {
        this.coupon = coupon;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public List<OrderCoupon> getOrderCoupons() {
        return this.orderCoupons;
    }

    public void setOrderCoupons(List<OrderCoupon> orderCoupons) {
        this.orderCoupons = orderCoupons;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public OrderCoupon addOrderCoupon(OrderCoupon orderCoupon) {
        getOrderCoupons().add(orderCoupon);
        orderCoupon.setCouponDetail(this);

        return orderCoupon;
    }

    public OrderCoupon removeOrderCoupon(OrderCoupon orderCoupon) {
        getOrderCoupons().remove(orderCoupon);
        orderCoupon.setCouponDetail(null);

        return orderCoupon;
    }

    public Date getConsumedTime() {
        return consumedTime;
    }

    public void setConsumedTime(Date consumedTime) {
        this.consumedTime = consumedTime;
    }

    public String getRuleCode() {
        return ruleCode;
    }

    public void setRuleCode(String ruleCode) {
        this.ruleCode = ruleCode;
    }

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    public String getConsumeCode() {
        return consumeCode;
    }

    public void setConsumeCode(String consumeCode) {
        this.consumeCode = consumeCode;
    }

    public Date getGeneratedTime() {
        return generatedTime;
    }

    public void setGeneratedTime(Date generatedTime) {
        this.generatedTime = generatedTime;
    }

    public BigInteger getBonusPoints() {
        return bonusPoints;
    }

    public void setBonusPoints(BigInteger bonusPoints) {
        this.bonusPoints = bonusPoints;
    }
}